/*
 *  Getris -- A Tetris game written in Groovy.
 *  Copyright (C) 2008 Johnny Jian
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package cn.johnnyjian.getris.game.color

import cn.johnnyjian.getris.game.Container
import java.awt.Color

class ColorfulQuadrelUtils {

	public static final COLORS = [
		new Color(0, 200, 255),
		new Color(255, 0, 0),
		new Color(255, 150, 0),
		new Color(0, 200, 0),
		new Color(40, 0, 240),
		new Color(210, 0, 240),
		new Color(255, 255, 0)
	]

	static registerColorfulQuadrels() {
		Container.QUADRELS.eachWithIndex { quadrelClass, i ->
			def metaClass = quadrelClass.metaClass

			metaClass.getColor = { -> COLORS[i] }

			def copyOrRemove = { name, color, container, x, y ->
				delegate.metaClass.invokeMethod(delegate.class, delegate, name, [container, x, y] as Object[], true, false)
				delegate.eachSquare { xb, yb ->
					container.setColorAt x + xb, y + yb, color
				}
			}
			metaClass.copyTo = copyOrRemove.curry('copyTo', COLORS[i])
			metaClass.removeFrom = copyOrRemove.curry('removeFrom', null)
		}
	}

}
